package cn.hd.commonService.handler;


import cn.hd.commonService.vo.Result;
import cn.hd.commonService.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 定义全局异常处理
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 处理未知的业务异常
     * @param e
     * @return
     */
    @ExceptionHandler(value =Exception.class)
    @ResponseBody
    public Result exceptionHandler(Exception e){
        CustomException customException = CustomException.cloneException(e);
        log.error("原因是:",e);
        return Result.defineError(customException);
    }
}
